package convertedio;

import java.io.*;
import java.util.ArrayList;

public class ConvertedDemo6 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("罗志祥", 16);
        Student s2 = new Student("张三", 23);
        Student s3 = new Student("林则徐", 24);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("F:\\11\\d.txt"));
        // 方式二
        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        // 往本地文件中写的是一个集合
        oos.writeObject(list);

        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("F:\\11\\d.txt"));
        ArrayList<Student> list2 = (ArrayList<Student>) ois.readObject();
        for (Student student : list2) {
            System.out.println(student);
        }
        ois.close();
    }
}
